// https://leetcode.cn/problems/remove-outermost-parentheses/
// Created by ade on 2022/10/25.
//
#include <string>
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    string removeOuterParentheses(string s) {
        string res = "";
        vector<char> st = {};
        for (int i = 0; i < s.size(); i++) {
            if (st.empty()) {
                st.push_back(s[i]);
                continue;
            }
            if (s[i] == '(') {
                st.push_back(s[i]);
                res += "(";
                continue;
            }
            st.pop_back();
            if (!st.empty()) {
                res += ")";
            }
        }
        return res;
    }
};

int main() {
    Solution so;
    string nums = "(()())(())(()(()))";
    cout << so.removeOuterParentheses(nums);

    return 0;
}